/* **********************************************************************************
 *
 * Copyright (c) Microsoft Corporation. All rights reserved.
 *
 * This source code is subject to terms and conditions of the Microsoft Public
 * License (Ms-PL). A copy of the license can be found in the license.htm file
 * included in this distribution.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * **********************************************************************************/

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Hosting;

namespace Cassinipp.WebServer
{
	//
	// Internal class provides helpers for string formatting of HTTP responses
	//
	internal static class Messages
	{
		private const string _httpErrorFormat1 =
			@"<html>
    <head>
        <title>{0}</title>
";

		public static string VersionString = typeof (Server).Assembly.GetName().Version.ToString();

		public const string EmbeddedStyleSheet =
			@"        <style>
        	body {font-family:""Verdana"";font-weight:normal;font-size: 8pt;color:black;} 
        	p {font-family:""Verdana"";font-weight:normal;color:black;margin-top: -5px}
        	b {font-family:""Verdana"";font-weight:bold;color:black;margin-top: -5px}
        	h1 { font-family:""Verdana"";font-weight:normal;font-size:18pt;color:red }
        	h2 { font-family:""Verdana"";font-weight:normal;font-size:14pt;color:maroon }
        	pre {font-family:""Lucida Console"";font-size: 8pt}
        	.marker {font-weight: bold; color: black;text-decoration: none;}
        	.version {color: gray;}
        	.error {margin-bottom: 10px;}
        	.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
";

		private static string _httpErrorFormat2 =
			@"    </head>
    <body bgcolor=""white"">

            <span><h1>Server Error in '{0}' Application.<hr width=100% size=1 color=silver></h1>

            <h2> <i>HTTP Error {1} - {2}.</i> </h2></span>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b>&nbsp;Cassini Web Server " +
			VersionString + @"

            </font>

    </body>
</html>
";




		public static string FormatErrorMessageBody(int statusCode, string appName)
		{
			string desc = HttpWorkerRequest.GetStatusDescription(statusCode);

			return string.Format(_httpErrorFormat1, desc)
                   + EmbeddedStyleSheet
			       + string.Format(_httpErrorFormat2, appName, statusCode, desc);
		}
	}
}